﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Clandestine.Battle.Enemies
{
    public class BadassMotherfucker : Enemy
    {

        public BadassMotherfucker()
            : base("Badass Motherfucker", "badass_motherfucker.png")
        {
            base.HP = 400;
        }

        public override void TakeTurn(BattleController battle)
        {
            // Normally, a monster could choose between a basic attack, casting a spell etc. in here, then call that function.
            // For now, we'll just Attack!
            this.attack(battle);
        }

        private void attack(BattleController battle)
        {
            // Here we'd choose between our many types of attack.
            attackNomnomnom(battle);
        }

        private void attackNomnomnom(BattleController battle)
        {
            // Load image we need
            AnimatedSprite ballChain = new AnimatedSprite();
            ballChain.AddAnimation("Nom", new Animation("nomnomnom.png", 205, 63, 0, 0, 0, 1));
            ballChain.Interval = 90;
            ballChain.Visible = false;
            
            // Choose target
            Random rand = new Random(System.DateTime.Now.Millisecond); // Not v. random >.>
            Combatant target = battle.Players[rand.Next(battle.Players.Count)];
            
            // Damage [Debug]
            int damage = 150;

            // Animation
            battle.Queue.Add(delegate
            {
                MessageWindow.SetText("{0} attacks {1} with Ball 'n' Chain!", 3000, this.Name, target.Name);

                // Move 
                Point origin = this.Sprite.Position;
                Point dest = new Point(target.Sprite.X - 200, target.Sprite.Y + (target.Sprite.UnscaledHeight / 2) - (this.Sprite.UnscaledHeight / 2));
                RatioTimedEvent move = delegate (float r, float dR) {
                    this.Sprite.X += (int)((dest.X - origin.X) * dR);
                    this.Sprite.Y += (int)((dest.Y - origin.Y) * dR);
                };
                Ticker.AddTimer(move, 2000);

                // Nom nom nom!
                ballChain.X = this.Sprite.X + 90;
                ballChain.Y = this.Sprite.Y + 48 - (ballChain.UnscaledHeight/2);
                ballChain.Layer = Math.Max(this.Sprite.Layer + 1, target.Sprite.Layer + 1);
                ballChain.Visible = true;
                ballChain.Playing = true;
                Ticker.AddTimer(null, 1000);
                ballChain.Visible = false;
                target.TakeDamage(damage);

                // Move back
                RatioTimedEvent moveBack = delegate(float r, float dR)
                {
                    this.Sprite.X -= (int)((dest.X - origin.X) * dR);
                    this.Sprite.Y -= (int)((dest.Y - origin.Y) * dR);
                };
                Ticker.AddTimer(moveBack, 2000);

                MessageWindow.ClearText();
                ballChain.Dispose();
            });

        }
        
    }
}
